<?

/* 
 * View implementation for the GameView controller
 */ 
include_once('lib/combat.php');
$playerIsReady = $this->character->checkStatus();
$ap = $this->character->getCharacterStat('AP');

?>
<table width="100%" cellpadding="0" cellspading="0"><tr>
  <td valign="top" width="*">
    <?
    // display various banners
    if ($ap <= 0)
    {
      ?><div class="banner"><b>You don't have enough Action Points (AP) right now.</b> You'll
        have to wait a minute or two until they start coming back. Or you
        could spend <b><a href="<?= actionUrl('cheat', 'meta') ?>">Cheat Points</a></b> to fully power up right away!</div><?
    }
    else if (!$playerIsReady)
    {
      ?><div class="banner"><b>You are too weak to do anything right now!</b><br/>
        You'll have to wait until you regained some HP, first. Maybe you can
        <a class="linkbutton" href="<?= actionUrl('index', 'shop') ?>">buy</a> 
        a healing potion or something from the local vendor?</div><?
    }    
    ?>
    
    <div id="zone_description">
      <?= nl2br($this->model->zoneDS['z_description']) ?>
      <?= getDefault($this->model->zoneMessage) ?>
    </div>
    
    <?
    if (isset($this->model->moveNextButton))
    {
      ?><div id="zone_description"><a class="linkbutton" href="<?= actionUrl('index', 'game') ?>"><?= $this->model->moveNextButton ?></a></div><?
    }
    ?>
    
    <table id="action_list" width="460">
    <?
      foreach($this->model->getActionListForZone($this->selectedAction) as $act)
      {
        $apCost = getDefault($act['a_cost'], 1);
        $dropList = $this->model->getDrops($act);
        $action_stats = TextToStringList($act['a_stats']);
        $xpCount = 0;
        $mobList = array();
        if (is_array($act['mobs']))
          foreach ($act['mobs'] as $mobDS)
          {
            $mobList[$mobDS['c_key']] = array(
              'count' => $mobList[$mobDS['c_key']]['count']+1,
              'name' => $mobDS['c_name'],
              'level' => $mobDS['c_level'],
              );
            calcXPRewardForMobDS($mobDS, $xpCount, $this->character->level);
          }
        calcXPRewardOther($act['a_xp'], $this->character->level, $xpCount);
        ob_start(); 
        $preMet = $this->model->printPrerequisites($act['a_prereqs'], $this->character);
        $prereqs = ob_get_clean();
        if ($action_stats['autohide'] == 'true' && !$preMet)
        {
        
        }
        else
        {
          if ($act['a_type'] == 'Q')
          {
            ob_start();
            include('custom/game.index.quest.php');
            $quests .= ob_get_clean(); 
          }
          else
            include('custom/game.index.action.php');
        }
      }
    ?>
    </table>      
  </td>
  
  <td valign="top">
    &nbsp;&nbsp;  
  </td>
  
  <td valign="top" width="260">
    <?
      print('<img class="zone_image" src="img/zones/'.$this->model->zoneDS['z_icon'].'.png"/><br/>&nbsp;');
    
      if ($this->character->getCharacterStat('MP') > 0)
      {
        include('custom/game.index.spell.php');
      }
    
    ?>  
    
    <div id="questlist">
      <?
      if (trim($quests) != '') 
      {
      ?>
      <h2>Quests</h2>
      <table width="100%" cellspacing="0" cellpadding="0">
      <?= $quests ?>
      </table>
      <?
      }
      ?>
    </div>
  </td> 
       
</tr></table>
<script>
  function refreshPage()
  {
    document.location.replace('<?= actionUrl('index', 'game') ?>');
  }
  window.setTimeout('refreshPage()', <?= $this->character->tickTime*1000 ?>);
</script>
